package com.loukou.lkt.lkt.dao;

import java.util.Date;
import java.util.List;

import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.transaction.annotation.Transactional;

import com.loukou.lkt.lkt.entity.PoPurchaseOrder;

public interface PoPurchaseOrderDao extends PagingAndSortingRepository<PoPurchaseOrder, Integer>{

	PoPurchaseOrder findByOrderCode(String orderCode);

	@Modifying
	@Transactional
	@Query("update PoPurchaseOrder set purchaseInOrderId = ?2,actualArrivetime = ?3,orderState = ?4,receiveUserName = ?5,receiveTime = ?6 where id = ?1")
	void updatePoPurchaseOrderForApi(int id,int purchaseInOrderId,Date actualArrivetime,int orderState,String receiveUserName,Date receiveTime);

	List<PoPurchaseOrder> findBySupplierIdIn(List<Integer> supplierIdList);


	List<PoPurchaseOrder> findByOrderState(int i);
	
	List<PoPurchaseOrder> findByOrderStateAndSettmentType(int orderState,int settmentType);
	
	List<PoPurchaseOrder> findByOrderStateAndSettmentTypeNot(int orderState,int settmentType);

	@Modifying
	@Transactional
	@Query("update PoPurchaseOrder set prePayAmount = ?2,discount = ?3,planArrivetime = ?4,address = ?5,remark = ?6,warehouseId = ?7,settmentType=?8  where id = ?1")
	int updateOrder(int id, double prePayAmount, double discount, Date planArrivetime,
			String address, String remark, int warehouseId, int settmentType);

	List<PoPurchaseOrder> findBySupplierIdAndWarehouseId(int supplierId,
			int warehouseId);

	List<PoPurchaseOrder> findBySupplierIdAndWarehouseIdAndOrderStateIn(
			int supplierId, int warehouseId, List<Integer> states);
		
	@Modifying
	@Transactional
	@Query("update PoPurchaseOrder set orderState = ?1 where id = ?1")
	int updateOrderStateById(int orderState,int purchaseOrderId);

}
